<template>
  <div class="content-detail">
    <el-card class="card-box">
      <template #header>
        <div class="card-box-header">
          <span>基础信息</span>
          <div v-if="show1" @click="show1 = !show1" class="header-btn">
            <span>收起</span><i class="ml10 snowfont icon-shouqi"></i>
          </div>
          <div v-else @click="show1 = !show1" class="header-btn">
            <span>展开</span><i class="ml10 snowfont icon-zhankai"></i>
          </div>
        </div>
      </template>
      <el-collapse-transition>
        <flow-basic-info
          :basicInfoData="formBaseInfo"
          v-show="show1"
          :module="module"
          :billNum="billNum"
        />
      </el-collapse-transition>
    </el-card>

    <el-card class="card-box">
      <template #header>
        <div class="card-box-header">
          <span>检查/检验信息</span>
          <div v-if="show7" @click="show7 = !show7" class="header-btn">
            <span>收起</span><i class="ml10 snowfont icon-shouqi"></i>
          </div>
          <div v-else @click="show7 = !show7" class="header-btn">
            <span>展开</span><i class="ml10 snowfont icon-zhankai"></i>
          </div>
        </div>
      </template>
      <el-collapse-transition>
        <check-basic-info :basicInfoData="formBaseInfo" v-show="show7" />
      </el-collapse-transition>
    </el-card>

    <el-card class="card-box">
      <template #header>
        <div class="card-box-header">
          <span>流程状态</span>
          <div v-if="show4" @click="show4 = !show4" class="header-btn">
            <span>收起</span><i class="ml10 snowfont icon-shouqi"></i>
          </div>
          <div v-else @click="show4 = !show4" class="header-btn">
            <span>展开</span><i class="ml10 snowfont icon-zhankai"></i>
          </div>
        </div>
      </template>
      <el-collapse-transition>
        <status-info
          :jumpNode="jumpNode"
          :currentStep="currentStep"
          :steps="steps"
          :isChargehand="isChargehand"
          jumpStep="副厂长"
          v-show="show4"
        />
      </el-collapse-transition>
    </el-card>
    <el-card class="card-box" v-if="isEdit">
      <template #header>
        <div class="card-box-header">
          <span>待处理</span>

          <div v-if="show5" @click="show5 = !show5" class="header-btn">
            <span>收起</span><i class="ml10 snowfont icon-shouqi"></i>
          </div>
          <div v-else @click="show5 = !show5" class="header-btn">
            <span>展开</span><i class="ml10 snowfont icon-zhankai"></i>
          </div>
        </div>
      </template>

      <div v-if="show5 && flowType !== '1030'" class="content-box">
        <el-form
          ref="flowFormRef"
          :model="flowFormData"
          :rules="fromRules"
          label-width="140px"
          class="form__content"
        >
          <el-form-item :label="comments" prop="approvalComments" v-if="isEdit">
            <el-input
              type="textarea"
              :rows="4"
              placeholder="请输入内容"
              v-model="flowFormData.approvalComments"
            ></el-input>
          </el-form-item>

          <el-form-item :label="attachment">
            <ecm-upload
              :files="flowFormData.defaultFileList"
              @set-file="
                fileList => {
                  handleChange(fileList);
                }
              "
            ></ecm-upload>
          </el-form-item>
        </el-form>
        <div class="form__footer right-align-box" v-if="isEdit">
          <el-button @click="handleBack">取 消</el-button>
          <el-button
            type="primary"
            @click="handleTransfer"
            v-if="nodeDefId !== 'ACT_010'"
            >转 办</el-button
          >
          <el-button
            v-if="nodeDefId !== 'ACT_010'"
            type="danger"
            @click="handleReject"
            >驳 回</el-button
          >
          <!-- <el-button
            v-if="
              flowType === '1015' &&
              nodeDefId !== 'ACT_010' &&
              nodeDefId !== 'ACT_011'
            "
            type="danger"
            @click="handleReject"
            >驳 回</el-button
          >
          <el-button
            v-if="flowType !== '1015' && nodeDefId !== 'ACT_010'"
            type="danger"
            @click="handleReject"
            >驳 回</el-button
          > -->
          <el-button type="primary" @click="inform">知会</el-button>
          <el-button type="primary" @click="handleSave">保 存</el-button>
          <el-button type="primary" @click="handleSubmit">提 交</el-button>
        </div>
      </div>

      <!-- 安全文明 start -->
      <div v-if="show5 && flowType === '1030'" class="content-box">
        <el-form
          v-if="nodeDefId !== 'ACT_010'"
          ref="flowFormRef"
          :model="flowFormData"
          :rules="fromRules"
          label-width="140px"
          class="form__content"
        >
          <el-form-item :label="comments" prop="approvalComments" v-if="isEdit">
            <el-input
              type="textarea"
              :rows="4"
              placeholder="请输入内容"
              v-model="flowFormData.approvalComments"
            ></el-input>
          </el-form-item>

          <el-form-item :label="attachment">
            <ecm-upload
              :files="flowFormData.defaultFileList"
              @set-file="
                fileList => {
                  handleChange(fileList);
                }
              "
            ></ecm-upload>
          </el-form-item>
        </el-form>
        <el-form
          v-else
          ref="flowFormRef"
          :model="flowFormData"
          :rules="fromRules"
          label-width="200px"
          class="form__content"
        >
          <el-form-item
            :label="item.formTitle"
            v-for="(item, index) in flowFormData.dynamicForms || []"
            :key="index"
          >
            <template #label>
              <p class="form-item-title">
                <span style="color: #c45656; margin-right: 4px">*</span
                >{{ item.formTitle }}
                <el-tooltip
                  class="box-item"
                  effect="dark"
                  :content="item.formTitleDetails"
                  placement="top-start"
                >
                  <i class="el-icon-question" size="24"></i>
                </el-tooltip>
              </p>
            </template>
            <ecm-image-upload
              :files="flowFormData.dynamicForms[index]['attList']"
              @set-file="
                fileList => {
                  handleChange(fileList, index);
                }
              "
            ></ecm-image-upload>

            <div v-if="tipError[index]" class="error-tip">请上传照片</div>
          </el-form-item>
          <el-form-item label="其他照片" prop="otherAttachment">
            <ecm-image-upload
              :files="flowFormData.otherAttachment"
              @set-file="
                fileList => {
                  handleChange(fileList, 'other');
                }
              "
            ></ecm-image-upload>
          </el-form-item>
          <el-form-item label="检查小结">
            <el-input
              type="textarea"
              v-model="flowFormData.ext1"
              :rows="3"
            ></el-input>
          </el-form-item>
        </el-form>

        <div class="form__footer right-align-box" v-if="isEdit">
          <el-button @click="handleBack">取 消</el-button>
          <el-button type="primary" @click="handleTransfer">转 办</el-button>
          <!-- 在ACT_010 ACT_011隐藏质量检查的驳回按钮 -->
          <!-- <el-button
            v-if="nodeDefId !== 'ACT_010'"
            type="danger"
            @click="handleReject"
            >驳 回</el-button
          > -->
          <el-button
            v-if="
              flowType === '1015' &&
              nodeDefId !== 'ACT_010' &&
              nodeDefId !== 'ACT_011'
            "
            type="danger"
            @click="handleReject"
            >驳 回</el-button
          >
          <el-button
            v-if="flowType !== '1015' && nodeDefId !== 'ACT_010'"
            type="danger"
            @click="handleReject"
            >驳 回</el-button
          >
          <el-button type="primary" @click="handleSave">保 存</el-button>
          <el-button type="primary" @click="inform">知会</el-button>
          <el-button type="primary" @click="handleSubmit">提 交</el-button>
        </div>
      </div>
      <!-- 安全文明 end -->
    </el-card>
    <el-card class="card-box">
      <template #header>
        <div class="card-box-header">
          <span>流转记录</span>
          <div v-if="show6" @click="show6 = !show6" class="header-btn">
            <span>收起</span><i class="ml10 snowfont icon-shouqi"></i>
          </div>
          <div v-else @click="show6 = !show6" class="header-btn">
            <span>展开</span><i class="ml10 snowfont icon-zhankai"></i>
          </div>
        </div>
      </template>
      <el-collapse-transition>
        <flow-info
          v-show="show6"
          :instanceId="instanceIdFlow"
          :nodeDefId="nodeDefId"
        />
      </el-collapse-transition>
    </el-card>
    <el-dialog
      title="选择人员"
      v-model="dialogVisibleTransferAdd"
      width="920px"
    >
      <add-user
        v-model:dialogVisibleTransferAdd="dialogVisibleTransferAdd"
        :currentUsers="acceptUsers"
        :isSingle="true"
        @emitAddUser="showNextJump"
      />
    </el-dialog>
    <el-dialog
      title="驳回"
      v-model="dialogVisible"
      destroy-on-close
      width="600px"
    >
      <reject-view
        v-model:dialogVisible="dialogVisible"
        :taskId="taskIdMain"
        :module="module"
        :formBaseInfo="formBaseInfo"
      />
    </el-dialog>

    <el-dialog
      title="下一步流转至"
      v-model="dialogVisibleNext"
      destroy-on-close
      width="600px"
    >
      <div class="next-content">
        <el-radio-group
          v-if="nextJumpToArr && nextJumpToArr.length"
          v-model="nextJumpToId"
        >
          <el-radio
            v-for="item in nextJumpToArr"
            :key="item.id"
            :label="item.id"
            border
            @change="changeNextJump"
            >{{ item.name }}</el-radio
          >
        </el-radio-group>
      </div>

      <div class="form__footer">
        <el-button @click="dialogVisibleNext = false">取 消</el-button>
        <el-button type="primary" @click="handleNextJump">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import { ref, watchEffect } from "vue";
import { useRouter } from "vue-router";
import { ProcessStatusEnum } from "./types";
import NotifMessage from "/@/utils/message/notification";
import StatusInfo from "/@/views/approval/components/processInfo/StatusInfo.vue";
import FlowInfo from "/@/views/approval/components/processInfo/FlowInfo.vue";
import FlowBasicInfo from "./components/flowBasicInfo.vue";
import CheckBasicInfo from "../components/processInfo/CheckBasicInfo.vue";
import AddUser from "/@/views/projectsA/acceptance/concealed/components/dialog/AddUser.vue";
import RejectView from "./components/rejectView.vue";
import ecmUpload from "/@/components/ecmUpload/index.vue";
import ecmImageUpload from "/@/components/ecmImage/index.vue";
import { onFilterFileData, onInitFileList } from "/@/utils/file";
import { storageLocal } from "/@/utils/storage";
import {
  qtyFlowInfo,
  flowSubmit,
  civilizFlowInfo,
  civilizUpdate,
  civilizFlowSubmit
} from "/@/api/construction";
import { transfer, postSaveDraft, getDraft } from "/@/api/projects";
import { flowTypeObj } from "./type";
import { clickEvent } from "/@/utils/func";
import { flowNotifyRead, flowNotify } from "/@/api/work";
import { postApproveHistory } from "/@/api/acceptance";

const props = defineProps({
  instanceId: {
    type: Number,
    default: 0
  },
  flowId: {
    type: Number || String,
    default: ""
  },
  flowType: {
    type: Number || String,
    default: "1015"
  },
  taskId: {
    type: Number || String,
    default: ""
  },
  contractId: {
    type: Number,
    required: true,
    default: 0
  },
  nodeDefId: {
    type: String,
    required: true,
    default: "ACT_010"
  },
  isEdit: {
    type: Boolean,
    required: true,
    default: false
  },
  module: {
    type: String,
    default: "quality"
  },
  billName: {
    type: String,
    default: ""
  },
  readId: {
    type: String,
    default: ""
  },
  approvalType: {
    type: String,
    default: ""
  },
  source: {
    type: String,
    default: ""
  },
  billNum: {
    type: String,
    default: ""
  }
});
const router = useRouter();
let currentStep = ref(ProcessStatusEnum.ACT_010);
const flowFormRef = ref<HTMLFormElement | null>(null) as any;
let currentNode = ref("");
let instanceIdFlow = ref(); // 实例ID
let flowType = ref(props.flowType);
let steps = ref([]);
let nextJumpToArr = ref([]);
let nextJumpToId = ref("");
let formBaseInfo = ref<object>({}) as any; // 基础信息
let addUserInfo = ref<object>({}); // 人员选择器，所选择人员信息
let flowFormData = ref({
  approvalComments: "",
  defaultFileList: [],
  otherAttachment: [],
  ext1: "",
  dynamicForms: []
}); // 待处理信息
let dialogVisibleTransferAdd = ref(false); // 选择人员的弹窗是否显示
let dialogVisibleType = ref("submit");
let dialogVisible = ref(false); // 驳回弹窗是否展示
let dialogVisibleNext = ref(false);
let acceptUsers = ref([]); // 已选择人员
let taskIdMain = ref("");
let taskIdNotify = ref("");
let jumpNode = flowTypeObj[flowType.value].jumpNode;
let show1 = ref(true);
let show4 = ref(true);
let show5 = ref(true);
let show6 = ref(true);
let show7 = ref(true);
let isRequired = ref(true);
let isChargehand = ref("0");
const tipError = ref([]) as any;
let dynamicsOpinion = [];
let attachment = ref("附件");
let comments = ref("审批意见");
if (props.nodeDefId === "ACT_012") {
  attachment.value = "整改附件";
  comments.value = "整改意见";
}
if (props.nodeDefId === "ACT_013") {
  isRequired.value = false;
}
const validateFileList = (rule: any, value: any, callback: any) => {
  if (props.nodeDefId === "ACT_013") {
    callback();
  } else {
    if (!value.length) {
      return callback(new Error("请上传照片"));
    } else {
      callback();
    }
  }
};
const fromRules = ref({
  approvalComments: [
    { required: true, message: "请输入整改信息", trigger: "blur" }
  ],
  defaultFileList: [
    {
      validator: validateFileList,
      trigger: "change",
      required: isRequired.value
    }
  ]
});
// 进入详情进行判断节点位置
if (props.nodeDefId) {
  currentStep.value = ProcessStatusEnum[props.nodeDefId as string];
}

const handleSave = async () => {
  const { nodeDefId, flowId } = props;
  const params = {
    flowId: flowId,
    nodeId: nodeDefId,
    taskId: taskIdMain.value,
    formJson: JSON.stringify(flowFormData.value)
  };
  const { code, message } = await postSaveDraft(params);
  if (code === 200) {
    NotifMessage.success(message);
  } else {
    NotifMessage.error(message);
  }
};

const getFlowFormData = async () => {
  const { data } = await getDraft(taskIdMain.value);
  if (data?.formJson) {
    flowFormData.value = JSON.parse(data.formJson);
  }
};

// 基础信息获取
const getInitFlowInfo = async () => {
  const { contractId } = props;
  if (!contractId) {
    return;
  }
  const params = {
    id: contractId
  };
  const module = props.module;
  let apiFunctionName = module === "civiliz" ? civilizFlowInfo : qtyFlowInfo;
  const { code, data } = await apiFunctionName(params);
  if (code === 200) {
    formBaseInfo.value = data.formBaseInfo;
    isChargehand.value = formBaseInfo.value.isChargehand;
    taskIdMain.value = data.taskId;
    currentNode.value = flowTypeObj[flowType.value]?.curNodeName || ""; //某一节点的下一流程节点可选
    let nodeName = flowTypeObj[flowType.value].nodeName;
    nodeName.forEach(item => {
      steps.value.push({ step: item, title: item });
    });
    instanceIdFlow.value = formBaseInfo.value.instanceId;
    formBaseInfo.value.billName =
      formBaseInfo.value?.billName || props.billName;
    // 表单
    if (module === "civiliz" && props.nodeDefId === "ACT_010") {
      flowFormData.value.otherAttachment = onInitFileList(
        formBaseInfo.value.otherAttachment
      );
      let dynamicForms = formBaseInfo.value.dynamicForms || [];
      dynamicForms.map(item => {
        item.attList = onInitFileList(item.attList);
      });
      flowFormData.value.dynamicForms = dynamicForms;
      flowFormData.value.ext1 = formBaseInfo.value.ext1; // 检查小结
    }
    if (props.source === "self") {
      // 获取流程数据
      const { code, data } = await postApproveHistory({
        instanceId: instanceIdFlow.value
      });
      if (code === 200) {
        let length = data.length;
        taskIdNotify.value = length && data[length - 1]?.taskId;
      }
    }
    // flowFormData.value.approvalForm = approvals?.approvalForm;
    // flowFormData.value.defaultFileList = onInitFileList(
    //   data.formBaseInfo.flowStartAttachmentArr
    // );
    // props.isEdit && props.instanceId && getStorageTmpData();
  }
};

const handleChange = (fileList, num?: any) => {
  if (!num && num !== 0) {
    flowFormData.value.defaultFileList = fileList;
    flowFormRef.value.clearValidate("defaultFileList");
  } else {
    if (num === "other") {
      flowFormData.value.otherAttachment = fileList;
    } else {
      flowFormData.value.dynamicForms[num].attList = fileList;
      validataDynamic(num);
    }
  }
};

const validataDynamic = (num?) => {
  // 校验动态表单
  let tipFlag = false;
  if (num || num === 0) {
    let item = flowFormData.value.dynamicForms[num];
    if (!item.attList || (item.attList && item.attList.length === 0)) {
      tipError.value[num] = true;
      tipFlag = true;
    } else {
      tipError.value[num] = false;
    }
  } else {
    flowFormData.value.dynamicForms.map((item, index) => {
      if (!item.attList || (item.attList && item.attList.length === 0)) {
        tipError.value[index] = true;
        tipFlag = true;
      } else {
        tipError.value[index] = false;
      }
    });
  }
  return tipFlag;
};

//转办
const inform = async () => {
  dialogVisibleTransferAdd.value = true;
  dialogVisibleType.value = "inform";
};

//转办
const handleTransfer = async () => {
  dialogVisibleTransferAdd.value = true;
  dialogVisibleType.value = "transfer";
};

// 提交
const handleSubmit = async () => {
  // 最后一个节点不需要选择下一节点处理人,直接取当前登录人
  const isValid = await new Promise(resolve =>
    flowFormRef.value.validate(resolve)
  );
  if (!isValid) return;
  // 1030 安全文明第一个节点需要校验动态表单
  if (props.nodeDefId === "ACT_010" && props.module === "civiliz") {
    let tipFlag = validataDynamic();
    if (tipFlag) {
      return;
    }
  }
  let nodes = flowTypeObj[flowType.value].nodeId;
  if (props.nodeDefId === nodes[nodes.length - 1]) {
    emitAddUser();
  } else {
    if (currentNode.value === props.nodeDefId) {
      //当前节点的下一步节点是可选的
      nextJumpToArr.value = flowTypeObj[flowType.value]?.nextJumpToArr || [];
      if (nextJumpToArr.value && nextJumpToArr.value.length) {
        nextJumpToId.value = nextJumpToArr.value[0].id;
        isChargehand.value = nextJumpToArr.value[0].isChargehand;
      }
      dialogVisibleNext.value = true;
    } else {
      dialogVisibleTransferAdd.value = true;
      dialogVisibleType.value = "submit";
    }
  }
};

const showNextJump = parmas => {
  addUserInfo.value = parmas;
  if (dialogVisibleType.value === "submit") {
    // //审核通过
    // if (currentNode.value === props.nodeDefId) {
    //   //当前节点的下一步节点是可选的
    //   dialogVisibleTransferAdd.value = false;
    //   dialogVisibleNext.value = true;
    // } else {
    emitAddUser();
    // }
  } else if (dialogVisibleType.value === "transfer") {
    //转办
    submitTransfer(parmas);
  } else if (dialogVisibleType.value === "inform") {
    //知会
    submitInform(parmas);
  }
};

const submitInform = async parmas => {
  const userInfo = storageLocal.getItem("info");
  const { instanceId } = props;
  const notifys = [];
  const id = parmas?.idList[0].id;
  notifys.push(id);
  let params = {
    assignee: userInfo?.userId,
    instanceId,
    taskId: taskIdMain.value,
    notifys: notifys
  };
  try {
    const { code, message } = await flowNotify(params);
    if (code === 200) {
      NotifMessage.success(message);
      dialogVisible.value = false;
      handleBack();
    } else {
      NotifMessage.error(message);
    }
  } catch (err) {
    console.log(err);
  }
};

//确定下一步流程
const handleNextJump = () => {
  if (isChargehand.value === "0") {
    //下一步节点选择完成
    emitAddUser();
  } else {
    dialogVisibleNext.value = false;
    dialogVisibleType.value = "submit";
    dialogVisibleTransferAdd.value = true;
  }
  // emitAddUser();
};

const emitAddUser = () => {
  dialogVisibleTransferAdd.value = false;
  // 安全文明需要调用update接口
  const { module } = props;
  if (module === "civiliz") {
    submitUpdate();
  } else {
    toSubmit();
  }
};

// 更新
const submitUpdate = async () => {
  let params = {} as any;
  const { nodeDefId } = props;
  if (nodeDefId !== "ACT_010") {
    toSubmit();
    return;
  }
  // 处理动态表单的名称与附件问题
  let dynamicFormsArr = [];
  dynamicsOpinion.length = 0;
  flowFormData.value.dynamicForms.map(item => {
    let obj = {
      name: item.formTitle,
      tips: item.formTitleDetails,
      content: item.attList,
      type: "images"
    };
    dynamicsOpinion.push(obj);
    dynamicFormsArr.push({
      ...item,
      attList: onFilterFileData(item.attList)
    });
  });

  params = {
    id: formBaseInfo.value.id,
    otherAttachment: onFilterFileData(flowFormData.value.otherAttachment),
    dynamicForms: dynamicFormsArr,
    ext1: flowFormData.value.ext1
  };
  formBaseInfo.value.option = JSON.stringify([
    // 动态表单
    ...dynamicsOpinion,
    {
      name: "其他照片",
      content: flowFormData.value.otherAttachment,
      type: "files"
    },
    {
      name: "检查小结",
      content: flowFormData.value.ext1,
      type: "textarea"
    }
  ]);

  try {
    const { code, message } = await civilizUpdate(params);
    if (code === 200) {
      toSubmit(formBaseInfo.value.option);
    } else {
      NotifMessage.error(message);
    }
  } catch (err) {
    console.log(err);
  }
};

// 审批
const toSubmit = async (opinion?: any) => {
  const { nodeDefId, instanceId, flowId } = props;
  if (!instanceId) {
    return;
  }
  let formData = {
    approvalComments: flowFormData.value.approvalComments,
    approvalForm: flowFormData.value.approvalForm,
    templateAttachment: onFilterFileData(flowFormData.value.defaultFileList)
  };
  const info = storageLocal.getItem("info");
  let nodes = flowTypeObj[flowType.value].nodeId;
  //最后一个节点的下一步处理人为当前操作人
  const option = [
    {
      name: comments.value,
      content: formData.approvalComments,
      type: "textarea"
    },
    {
      name: attachment.value,
      content: flowFormData.value.defaultFileList,
      type: "images"
    }
  ];
  let nextHandleId =
    props.nodeDefId === nodes[nodes.length - 1] || isChargehand.value === "0"
      ? info?.userId
      : addUserInfo.value?.idList[0]?.id;
  let params = {
    formBaseInfo: {
      id: formBaseInfo.value.id,
      acceptUsers: nextHandleId
    },
    flowFormData: {
      approvalResult: "1",
      businessId: formBaseInfo.value.id,
      flowId: flowId,
      flowTypeCode: flowType.value,
      instanceId: instanceId,
      nodeId: nodeDefId,
      projectManageId: storageLocal.getItem("projectInfo")?.id
    },
    formSubMap: {
      flowType: flowType.value,
      nodeId: nodeDefId,
      procInstId: instanceId,
      taskId: taskIdMain.value,
      opinion: opinion || JSON.stringify(option),
      assignee: nextHandleId,
      isChargehand: isChargehand.value || "0"
    },
    tmpStorage: {
      nodeId: nodeDefId,
      flowId,
      taskId: taskIdMain.value,
      handlerId: nextHandleId,
      userId: info ? info?.userId : "",
      valueJson: ""
    }
  };
  try {
    const module = props.module;
    const flowSubmitApi = module === "civiliz" ? civilizFlowSubmit : flowSubmit;
    const { code, message } = await flowSubmitApi(params);
    if (code === 200) {
      let text =
        module === "civiliz" ? "安全文明检查详情" : "施工质量检查审批详情";
      clickEvent(
        text,
        "提交",
        `流程审批_${formBaseInfo.value.billName}_${formBaseInfo.value?.flowMinType}`
      );
      NotifMessage.success(message);
      handleBack();
    } else {
      NotifMessage.error(message);
    }
  } catch (err) {
    console.log(err);
  }
};

const submitTransfer = async parmas => {
  const info = storageLocal.getItem("info");
  const option = [{ name: "转办", content: "转办协助处理", type: "textarea" }];
  let params = {
    targetAssignee: parmas?.idList[0].id,
    opinion: JSON.stringify(option),
    instanceId: props.instanceId,
    taskId: taskIdMain.value,
    flowId: props.flowId,
    handlerId: info?.userId,
    handlerName: info?.name,
    businessTraParam: {
      id: formBaseInfo.value.id,
      acceptUsers: info?.userId,
      flowType: formBaseInfo.value?.flowMinType || props.flowType
    }
  };
  try {
    const { code, message } = await transfer(params);
    if (code === 200) {
      let text =
        props.module === "civiliz"
          ? "安全文明检查详情"
          : "施工质量检查审批详情";
      clickEvent(
        text,
        "转办",
        `流程审批_${formBaseInfo.value.billName}_${formBaseInfo.value?.flowMinType}`
      );
      NotifMessage.success(message);
      handleBack();
    } else {
      NotifMessage.error(message);
    }
  } catch (err) {
    console.log(err);
  }
};

//选择下一步流程节点
const changeNextJump = async id => {
  nextJumpToArr.value.forEach(item => {
    if (item.id === id) {
      formBaseInfo.value.isChargehand = item.isChargehand;
      isChargehand.value = item.isChargehand;
    }
  });
};

// 返回按钮事件
const handleBack = () => {
  router.push("/approval/todo");
};

const handleReject = () => {
  dialogVisible.value = true;
};

//待阅转为已阅
const submitFlowNotifyRead = async () => {
  const info = storageLocal.getItem("info");
  let { instanceId, taskId, readId } = props;
  let params = {
    assignee: info?.userId,
    instanceId,
    taskId,
    id: readId
  };
  try {
    const { code, message } = await flowNotifyRead(params);
    if (code !== 200) {
      message && NotifMessage.error(message);
    }
  } catch (err) {
    console.log(err);
  }
};
watchEffect(() => {
  if (taskIdMain.value) {
    getFlowFormData();
  }
});
getInitFlowInfo();
if (props.approvalType === "notify") {
  submitFlowNotifyRead();
}
defineExpose({ getInitFlowInfo, isChargehand, taskIdMain, taskIdNotify });
// });
</script>

<style lang="scss" scoped>
.content-detail :deep .el-dialog .form__footer {
  text-align: right;
}
.next-content {
  padding: 10px 20px;
}
.error-tip {
  color: #e45d5d;
  font-size: 12px;
}
</style>
